﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

using Microsoft.Drawing;

namespace Spencen.Mobile.UI.Primitives
{
    public class ImageElement : RectangleElement
    {
        public ImageElement()
        {
            Background = null;
        }

        public Image Source { get; set; }

        protected override void OnRender( GraphicsContext context )
        {
            base.OnRender( context );

            if ( Source != null )
            {
                var points = GeneratePoints();

                points = context.TransformedPoints( points );

                var transformedRectangle = new Rectangle( points.Min( p => p.X ), points.Min( p => p.Y ), Math.Abs( points[ 2 ].X - points[ 0 ].X ), Math.Abs( points[ 2 ].Y - points[ 0 ].Y ) );
                context.Graphics.DrawImage( Source, transformedRectangle, new Rectangle( 0, 0, transformedRectangle.Width, transformedRectangle.Height ), GraphicsUnit.Pixel );
                // context.Graphics.DrawImageTransparent( Source, transformedRectangle );
            }
        }

        public override bool SupportsRotation {  get { return false; } }
    }
}
